package Test;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ActionListenerTest {

    private  static  void Test05(){
        JFrame jFrame = new JFrame();
        jFrame.setSize(500,500);
        jFrame.setVisible(true);
        jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        JButton but = new JButton("点击");  //1.创建按钮组件作为事件源
        but.addActionListener(new click());     //3.为事件源注册自定义监听器绑定
        jFrame.add(but);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(ActionListenerTest::Test05);
    }
}

//2.自定义事件监听类
class click implements ActionListener {
    @Override
    public void actionPerformed(ActionEvent e) {     //4.实现监听器方法，对监听事件进行处理
        System.out.println("点击按钮");
    }
}